/*** BNFC-Generated Pretty Printer and Abstract Syntax Viewer ***/

#include "Printer.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int _n_;
char* buf_;
int cur_;
int buf_size;

/* You may wish to change the renderC functions */
void renderC(Char c)
{
  if (c == '{')
  {
     bufAppendC('\n');
     indent();
     bufAppendC(c);
     _n_ = _n_ + 2;
     bufAppendC('\n');
     indent();
  }
  else if (c == '(' || c == '[')
     bufAppendC(c);
  else if (c == ')' || c == ']')
  {
     backup();
     bufAppendC(c);
     bufAppendC(' ');
  }
  else if (c == '}')
  {
     _n_ = _n_ - 2;
     backup();
     backup();
     bufAppendC(c);
     bufAppendC('\n');
     indent();
  }
  else if (c == ',')
  {
     backup();
     bufAppendC(c);
     bufAppendC(' ');
  }
  else if (c == ';')
  {
     backup();
     bufAppendC(c);
     bufAppendC('\n');
     indent();
  }
  else if (c == 0) return;
  else
  {
     bufAppendC(c);
     bufAppendC(' ');
  }
}
void renderS(String s)
{
  if(strlen(s) > 0)
  {
    bufAppendS(s);
    bufAppendC(' ');
  }
}
void indent(void)
{
  int n = _n_;
  while (n > 0)
  {
    bufAppendC(' ');
    n--;
  }
}
void backup(void)
{
  if (buf_[cur_ - 1] == ' ')
  {
    buf_[cur_ - 1] = 0;
    cur_--;
  }
}
char* printProgram(Program p)
{
  _n_ = 0;
  bufReset();
  ppProgram(p, 0);
  return buf_;
}
char* printStatement(Statement p)
{
  _n_ = 0;
  bufReset();
  ppStatement(p, 0);
  return buf_;
}
char* printQuery(Query p)
{
  _n_ = 0;
  bufReset();
  ppQuery(p, 0);
  return buf_;
}
char* printNested_query(Nested_query p)
{
  _n_ = 0;
  bufReset();
  ppNested_query(p, 0);
  return buf_;
}
char* printSpecifier(Specifier p)
{
  _n_ = 0;
  bufReset();
  ppSpecifier(p, 0);
  return buf_;
}
char* printListProjection(ListProjection p)
{
  _n_ = 0;
  bufReset();
  ppListProjection(p, 0);
  return buf_;
}
char* printProjection(Projection p)
{
  _n_ = 0;
  bufReset();
  ppProjection(p, 0);
  return buf_;
}
char* printReference(Reference p)
{
  _n_ = 0;
  bufReset();
  ppReference(p, 0);
  return buf_;
}
char* printRererence(Rererence p)
{
  _n_ = 0;
  bufReset();
  ppRererence(p, 0);
  return buf_;
}
char* printColumn_reference(Column_reference p)
{
  _n_ = 0;
  bufReset();
  ppColumn_reference(p, 0);
  return buf_;
}
char* printDot(Dot p)
{
  _n_ = 0;
  bufReset();
  ppDot(p, 0);
  return buf_;
}
char* printListVariable_declaration(ListVariable_declaration p)
{
  _n_ = 0;
  bufReset();
  ppListVariable_declaration(p, 0);
  return buf_;
}
char* printVariable_declaration(Variable_declaration p)
{
  _n_ = 0;
  bufReset();
  ppVariable_declaration(p, 0);
  return buf_;
}
char* printOptional_where_clause(Optional_where_clause p)
{
  _n_ = 0;
  bufReset();
  ppOptional_where_clause(p, 0);
  return buf_;
}
char* printCondition(Condition p)
{
  _n_ = 0;
  bufReset();
  ppCondition(p, 0);
  return buf_;
}
char* printPredicate(Predicate p)
{
  _n_ = 0;
  bufReset();
  ppPredicate(p, 0);
  return buf_;
}
char* printComparison_predicate(Comparison_predicate p)
{
  _n_ = 0;
  bufReset();
  ppComparison_predicate(p, 0);
  return buf_;
}
char* printComparison(Comparison p)
{
  _n_ = 0;
  bufReset();
  ppComparison(p, 0);
  return buf_;
}
char* printScalar_exp(Scalar_exp p)
{
  _n_ = 0;
  bufReset();
  ppScalar_exp(p, 0);
  return buf_;
}
char* printListAtom(ListAtom p)
{
  _n_ = 0;
  bufReset();
  ppListAtom(p, 0);
  return buf_;
}
char* printAtom(Atom p)
{
  _n_ = 0;
  bufReset();
  ppAtom(p, 0);
  return buf_;
}
char* printIn_predicate(In_predicate p)
{
  _n_ = 0;
  bufReset();
  ppIn_predicate(p, 0);
  return buf_;
}
char* printExists_predicate(Exists_predicate p)
{
  _n_ = 0;
  bufReset();
  ppExists_predicate(p, 0);
  return buf_;
}
char* printBetween_predicate(Between_predicate p)
{
  _n_ = 0;
  bufReset();
  ppBetween_predicate(p, 0);
  return buf_;
}
char* printLike_predicate(Like_predicate p)
{
  _n_ = 0;
  bufReset();
  ppLike_predicate(p, 0);
  return buf_;
}
char* printOptional_order_by_clause(Optional_order_by_clause p)
{
  _n_ = 0;
  bufReset();
  ppOptional_order_by_clause(p, 0);
  return buf_;
}
char* printListColumn_reference(ListColumn_reference p)
{
  _n_ = 0;
  bufReset();
  ppListColumn_reference(p, 0);
  return buf_;
}
char* printOptional_group_by_clause(Optional_group_by_clause p)
{
  _n_ = 0;
  bufReset();
  ppOptional_group_by_clause(p, 0);
  return buf_;
}
char* printOptional_ordering(Optional_ordering p)
{
  _n_ = 0;
  bufReset();
  ppOptional_ordering(p, 0);
  return buf_;
}
char* printOptional_having_clause(Optional_having_clause p)
{
  _n_ = 0;
  bufReset();
  ppOptional_having_clause(p, 0);
  return buf_;
}
char* printAggregate_condition(Aggregate_condition p)
{
  _n_ = 0;
  bufReset();
  ppAggregate_condition(p, 0);
  return buf_;
}
char* printFunction_reference(Function_reference p)
{
  _n_ = 0;
  bufReset();
  ppFunction_reference(p, 0);
  return buf_;
}
char* printFunction(Function p)
{
  _n_ = 0;
  bufReset();
  ppFunction(p, 0);
  return buf_;
}
char* showProgram(Program p)
{
  _n_ = 0;
  bufReset();
  shProgram(p);
  return buf_;
}
char* showStatement(Statement p)
{
  _n_ = 0;
  bufReset();
  shStatement(p);
  return buf_;
}
char* showQuery(Query p)
{
  _n_ = 0;
  bufReset();
  shQuery(p);
  return buf_;
}
char* showNested_query(Nested_query p)
{
  _n_ = 0;
  bufReset();
  shNested_query(p);
  return buf_;
}
char* showSpecifier(Specifier p)
{
  _n_ = 0;
  bufReset();
  shSpecifier(p);
  return buf_;
}
char* showListProjection(ListProjection p)
{
  _n_ = 0;
  bufReset();
  shListProjection(p);
  return buf_;
}
char* showProjection(Projection p)
{
  _n_ = 0;
  bufReset();
  shProjection(p);
  return buf_;
}
char* showReference(Reference p)
{
  _n_ = 0;
  bufReset();
  shReference(p);
  return buf_;
}
char* showRererence(Rererence p)
{
  _n_ = 0;
  bufReset();
  shRererence(p);
  return buf_;
}
char* showColumn_reference(Column_reference p)
{
  _n_ = 0;
  bufReset();
  shColumn_reference(p);
  return buf_;
}
char* showDot(Dot p)
{
  _n_ = 0;
  bufReset();
  shDot(p);
  return buf_;
}
char* showListVariable_declaration(ListVariable_declaration p)
{
  _n_ = 0;
  bufReset();
  shListVariable_declaration(p);
  return buf_;
}
char* showVariable_declaration(Variable_declaration p)
{
  _n_ = 0;
  bufReset();
  shVariable_declaration(p);
  return buf_;
}
char* showOptional_where_clause(Optional_where_clause p)
{
  _n_ = 0;
  bufReset();
  shOptional_where_clause(p);
  return buf_;
}
char* showCondition(Condition p)
{
  _n_ = 0;
  bufReset();
  shCondition(p);
  return buf_;
}
char* showPredicate(Predicate p)
{
  _n_ = 0;
  bufReset();
  shPredicate(p);
  return buf_;
}
char* showComparison_predicate(Comparison_predicate p)
{
  _n_ = 0;
  bufReset();
  shComparison_predicate(p);
  return buf_;
}
char* showComparison(Comparison p)
{
  _n_ = 0;
  bufReset();
  shComparison(p);
  return buf_;
}
char* showScalar_exp(Scalar_exp p)
{
  _n_ = 0;
  bufReset();
  shScalar_exp(p);
  return buf_;
}
char* showListAtom(ListAtom p)
{
  _n_ = 0;
  bufReset();
  shListAtom(p);
  return buf_;
}
char* showAtom(Atom p)
{
  _n_ = 0;
  bufReset();
  shAtom(p);
  return buf_;
}
char* showIn_predicate(In_predicate p)
{
  _n_ = 0;
  bufReset();
  shIn_predicate(p);
  return buf_;
}
char* showExists_predicate(Exists_predicate p)
{
  _n_ = 0;
  bufReset();
  shExists_predicate(p);
  return buf_;
}
char* showBetween_predicate(Between_predicate p)
{
  _n_ = 0;
  bufReset();
  shBetween_predicate(p);
  return buf_;
}
char* showLike_predicate(Like_predicate p)
{
  _n_ = 0;
  bufReset();
  shLike_predicate(p);
  return buf_;
}
char* showOptional_order_by_clause(Optional_order_by_clause p)
{
  _n_ = 0;
  bufReset();
  shOptional_order_by_clause(p);
  return buf_;
}
char* showListColumn_reference(ListColumn_reference p)
{
  _n_ = 0;
  bufReset();
  shListColumn_reference(p);
  return buf_;
}
char* showOptional_group_by_clause(Optional_group_by_clause p)
{
  _n_ = 0;
  bufReset();
  shOptional_group_by_clause(p);
  return buf_;
}
char* showOptional_ordering(Optional_ordering p)
{
  _n_ = 0;
  bufReset();
  shOptional_ordering(p);
  return buf_;
}
char* showOptional_having_clause(Optional_having_clause p)
{
  _n_ = 0;
  bufReset();
  shOptional_having_clause(p);
  return buf_;
}
char* showAggregate_condition(Aggregate_condition p)
{
  _n_ = 0;
  bufReset();
  shAggregate_condition(p);
  return buf_;
}
char* showFunction_reference(Function_reference p)
{
  _n_ = 0;
  bufReset();
  shFunction_reference(p);
  return buf_;
}
char* showFunction(Function p)
{
  _n_ = 0;
  bufReset();
  shFunction(p);
  return buf_;
}
void ppProgram(Program _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Progr:
    if (_i_ > 0) renderC(_L_PAREN);
    ppStatement(_p_->u.progr_.statement_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Program!\n");
    exit(1);
  }
}

void ppStatement(Statement _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Stmt:
    if (_i_ > 0) renderC(_L_PAREN);
    ppQuery(_p_->u.stmt_.query_, 0);
    ppIdent(_p_->u.stmt_.sc_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Statement!\n");
    exit(1);
  }
}

void ppQuery(Query _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Qry:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.qry_.select_, 0);
    ppSpecifier(_p_->u.qry_.specifier_, 0);
    ppProjection(_p_->u.qry_.projection_, 0);
    ppIdent(_p_->u.qry_.from_, 0);
    ppVariable_declaration(_p_->u.qry_.variable_declaration_, 0);
    ppOptional_where_clause(_p_->u.qry_.optional_where_clause_, 0);
    ppOptional_group_by_clause(_p_->u.qry_.optional_group_by_clause_, 0);
    ppOptional_having_clause(_p_->u.qry_.optional_having_clause_, 0);
    ppOptional_order_by_clause(_p_->u.qry_.optional_order_by_clause_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Query!\n");
    exit(1);
  }
}

void ppNested_query(Nested_query _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_NQry:
    if (_i_ > 0) renderC(_L_PAREN);
    renderC('(');
    ppQuery(_p_->u.nqry_.query_, 0);
    renderC(')');

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Nested_query!\n");
    exit(1);
  }
}

void ppSpecifier(Specifier _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Nospe:
    if (_i_ > 0) renderC(_L_PAREN);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Distn:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.distn_.distinct_, 0);
    ppSpecifier(_p_->u.distn_.specifier_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Specifier!\n");
    exit(1);
  }
}

void ppListProjection(ListProjection listprojection, int i)
{
  while(listprojection!= 0)
  {
    if (listprojection->listprojection_ == 0)
    {
      ppProjection(listprojection->projection_, 0);

      listprojection = 0;
    }
    else
    {
      ppProjection(listprojection->projection_, 0);
      renderC(',');
      listprojection = listprojection->listprojection_;
    }
  }
}

void ppProjection(Projection _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Parprj:
    if (_i_ > 0) renderC(_L_PAREN);
    renderC('(');
    ppProjection(_p_->u.parprj_.projection_, 0);
    renderC(')');

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Strprj:
    if (_i_ > 0) renderC(_L_PAREN);
    renderC('*');

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Refprj:
    if (_i_ > 0) renderC(_L_PAREN);
    ppReference(_p_->u.refprj_.reference_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Idprj:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.idprj_.identifier_, 0);
    renderC(':');
    ppReference(_p_->u.idprj_.reference_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Asprj:
    if (_i_ > 0) renderC(_L_PAREN);
    ppReference(_p_->u.asprj_.reference_, 0);
    ppIdent(_p_->u.asprj_.as_, 0);
    ppIdent(_p_->u.asprj_.identifier_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Plusprj:
    if (_i_ > 0) renderC(_L_PAREN);
    ppProjection(_p_->u.plusprj_.projection_1, 0);
    renderC('+');
    ppProjection(_p_->u.plusprj_.projection_2, 1);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Minprj:
    if (_i_ > 0) renderC(_L_PAREN);
    ppProjection(_p_->u.minprj_.projection_1, 0);
    renderC('-');
    ppProjection(_p_->u.minprj_.projection_2, 1);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Mulprj:
    if (_i_ > 1) renderC(_L_PAREN);
    ppProjection(_p_->u.mulprj_.projection_1, 1);
    renderC('*');
    ppProjection(_p_->u.mulprj_.projection_2, 2);

    if (_i_ > 1) renderC(_R_PAREN);
    break;

  case is_Divprj:
    if (_i_ > 1) renderC(_L_PAREN);
    ppProjection(_p_->u.divprj_.projection_1, 1);
    renderC('/');
    ppProjection(_p_->u.divprj_.projection_2, 2);

    if (_i_ > 1) renderC(_R_PAREN);
    break;

  case is_Modprj:
    if (_i_ > 1) renderC(_L_PAREN);
    ppProjection(_p_->u.modprj_.projection_1, 1);
    ppIdent(_p_->u.modprj_.mod_, 0);
    ppProjection(_p_->u.modprj_.projection_2, 2);

    if (_i_ > 1) renderC(_R_PAREN);
    break;

  case is_Refprjtw:
    if (_i_ > 2) renderC(_L_PAREN);
    ppReference(_p_->u.refprjtw_.reference_, 0);

    if (_i_ > 2) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Projection!\n");
    exit(1);
  }
}

void ppReference(Reference _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Colref:
    if (_i_ > 0) renderC(_L_PAREN);
    ppColumn_reference(_p_->u.colref_.column_reference_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Reference!\n");
    exit(1);
  }
}

void ppRererence(Rererence _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Funcref:
    if (_i_ > 0) renderC(_L_PAREN);
    ppFunction_reference(_p_->u.funcref_.function_reference_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Rererence!\n");
    exit(1);
  }
}

void ppColumn_reference(Column_reference _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Name:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.name_.identifier_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Namenst:
    if (_i_ > 0) renderC(_L_PAREN);
    ppColumn_reference(_p_->u.namenst_.column_reference_, 0);
    ppDot(_p_->u.namenst_.dot_, 0);
    ppIdent(_p_->u.namenst_.identifier_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Column_reference!\n");
    exit(1);
  }
}

void ppDot(Dot _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Dot:
    if (_i_ > 0) renderC(_L_PAREN);
    renderC('.');

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Ptr:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.ptr_.pointer_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Dot!\n");
    exit(1);
  }
}

void ppListVariable_declaration(ListVariable_declaration listvariable_declaration, int i)
{
  while(listvariable_declaration!= 0)
  {
    if (listvariable_declaration->listvariable_declaration_ == 0)
    {
      ppVariable_declaration(listvariable_declaration->variable_declaration_, 0);

      listvariable_declaration = 0;
    }
    else
    {
      ppVariable_declaration(listvariable_declaration->variable_declaration_, 0);
      renderS("");
      listvariable_declaration = listvariable_declaration->listvariable_declaration_;
    }
  }
}

void ppVariable_declaration(Variable_declaration _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Colrfas:
    if (_i_ > 0) renderC(_L_PAREN);
    ppColumn_reference(_p_->u.colrfas_.column_reference_, 0);
    ppIdent(_p_->u.colrfas_.as_, 0);
    ppIdent(_p_->u.colrfas_.identifier_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Colrfin:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.colrfin_.identifier_, 0);
    ppIdent(_p_->u.colrfin_.in_, 0);
    ppColumn_reference(_p_->u.colrfin_.column_reference_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Colrf:
    if (_i_ > 0) renderC(_L_PAREN);
    ppColumn_reference(_p_->u.colrf_.column_reference_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Variable_declaration!\n");
    exit(1);
  }
}

void ppOptional_where_clause(Optional_where_clause _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Nowhr:
    if (_i_ > 0) renderC(_L_PAREN);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Whrcls:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.whrcls_.where_, 0);
    ppCondition(_p_->u.whrcls_.condition_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Optional_where_clause!\n");
    exit(1);
  }
}

void ppCondition(Condition _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Paracnd:
    if (_i_ > 0) renderC(_L_PAREN);
    renderC('(');
    ppCondition(_p_->u.paracnd_.condition_, 0);
    renderC(')');

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Andcnd:
    if (_i_ > 0) renderC(_L_PAREN);
    ppCondition(_p_->u.andcnd_.condition_1, 0);
    ppIdent(_p_->u.andcnd_.and_, 0);
    ppCondition(_p_->u.andcnd_.condition_2, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Orcnd:
    if (_i_ > 0) renderC(_L_PAREN);
    ppCondition(_p_->u.orcnd_.condition_1, 0);
    ppIdent(_p_->u.orcnd_.or_, 0);
    ppCondition(_p_->u.orcnd_.condition_2, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Notcnd:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.notcnd_.not_, 0);
    ppCondition(_p_->u.notcnd_.condition_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Predcnd:
    if (_i_ > 0) renderC(_L_PAREN);
    ppPredicate(_p_->u.predcnd_.predicate_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Condition!\n");
    exit(1);
  }
}

void ppPredicate(Predicate _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Comp:
    if (_i_ > 0) renderC(_L_PAREN);
    ppComparison_predicate(_p_->u.comp_.comparison_predicate_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_In:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIn_predicate(_p_->u.in_.in_predicate_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Exts:
    if (_i_ > 0) renderC(_L_PAREN);
    ppExists_predicate(_p_->u.exts_.exists_predicate_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Bwn:
    if (_i_ > 0) renderC(_L_PAREN);
    ppBetween_predicate(_p_->u.bwn_.between_predicate_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Lik:
    if (_i_ > 0) renderC(_L_PAREN);
    ppLike_predicate(_p_->u.lik_.like_predicate_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Predicate!\n");
    exit(1);
  }
}

void ppComparison_predicate(Comparison_predicate _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_CompSca:
    if (_i_ > 0) renderC(_L_PAREN);
    ppScalar_exp(_p_->u.compsca_.scalar_exp_1, 0);
    ppComparison(_p_->u.compsca_.comparison_, 0);
    ppScalar_exp(_p_->u.compsca_.scalar_exp_2, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_CompNst:
    if (_i_ > 0) renderC(_L_PAREN);
    ppScalar_exp(_p_->u.compnst_.scalar_exp_, 0);
    ppComparison(_p_->u.compnst_.comparison_, 0);
    ppNested_query(_p_->u.compnst_.nested_query_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Comparison_predicate!\n");
    exit(1);
  }
}

void ppComparison(Comparison _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Eq:
    if (_i_ > 0) renderC(_L_PAREN);
    renderC('=');

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Neq:
    if (_i_ > 0) renderC(_L_PAREN);
    renderS("NE");

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Lt:
    if (_i_ > 0) renderC(_L_PAREN);
    renderC('<');

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Gt:
    if (_i_ > 0) renderC(_L_PAREN);
    renderC('>');

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Leq:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.leq_.le_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Geq:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.geq_.ge_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Comparison!\n");
    exit(1);
  }
}

void ppScalar_exp(Scalar_exp _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Atm:
    if (_i_ > 0) renderC(_L_PAREN);
    ppAtom(_p_->u.atm_.atom_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Colrftw:
    if (_i_ > 0) renderC(_L_PAREN);
    ppColumn_reference(_p_->u.colrftw_.column_reference_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Parsca:
    if (_i_ > 0) renderC(_L_PAREN);
    renderC('(');
    ppScalar_exp(_p_->u.parsca_.scalar_exp_, 0);
    renderC(')');

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Addsca:
    if (_i_ > 0) renderC(_L_PAREN);
    ppScalar_exp(_p_->u.addsca_.scalar_exp_1, 0);
    renderC('+');
    ppScalar_exp(_p_->u.addsca_.scalar_exp_2, 1);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Subsca:
    if (_i_ > 0) renderC(_L_PAREN);
    ppScalar_exp(_p_->u.subsca_.scalar_exp_1, 0);
    renderC('-');
    ppScalar_exp(_p_->u.subsca_.scalar_exp_2, 1);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Mulsca:
    if (_i_ > 1) renderC(_L_PAREN);
    ppScalar_exp(_p_->u.mulsca_.scalar_exp_1, 1);
    renderC('*');
    ppScalar_exp(_p_->u.mulsca_.scalar_exp_2, 2);

    if (_i_ > 1) renderC(_R_PAREN);
    break;

  case is_Divsca:
    if (_i_ > 1) renderC(_L_PAREN);
    ppScalar_exp(_p_->u.divsca_.scalar_exp_1, 1);
    ppIdent(_p_->u.divsca_.mod_, 0);
    ppScalar_exp(_p_->u.divsca_.scalar_exp_2, 2);

    if (_i_ > 1) renderC(_R_PAREN);
    break;

  case is_Andsca:
    if (_i_ > 1) renderC(_L_PAREN);
    ppScalar_exp(_p_->u.andsca_.scalar_exp_1, 1);
    renderC('&');
    ppScalar_exp(_p_->u.andsca_.scalar_exp_2, 2);

    if (_i_ > 1) renderC(_R_PAREN);
    break;

  case is_Orsca:
    if (_i_ > 1) renderC(_L_PAREN);
    ppScalar_exp(_p_->u.orsca_.scalar_exp_1, 1);
    renderC('|');
    ppScalar_exp(_p_->u.orsca_.scalar_exp_2, 2);

    if (_i_ > 1) renderC(_R_PAREN);
    break;

  case is_Notsca:
    if (_i_ > 1) renderC(_L_PAREN);
    ppScalar_exp(_p_->u.notsca_.scalar_exp_1, 1);
    renderC('^');
    ppScalar_exp(_p_->u.notsca_.scalar_exp_2, 2);

    if (_i_ > 1) renderC(_R_PAREN);
    break;

  case is_Lssca:
    if (_i_ > 2) renderC(_L_PAREN);
    ppScalar_exp(_p_->u.lssca_.scalar_exp_1, 2);
    ppIdent(_p_->u.lssca_.ls_, 0);
    ppScalar_exp(_p_->u.lssca_.scalar_exp_2, 3);

    if (_i_ > 2) renderC(_R_PAREN);
    break;

  case is_Rssca:
    if (_i_ > 2) renderC(_L_PAREN);
    ppScalar_exp(_p_->u.rssca_.scalar_exp_1, 2);
    ppIdent(_p_->u.rssca_.rs_, 0);
    ppScalar_exp(_p_->u.rssca_.scalar_exp_2, 3);

    if (_i_ > 2) renderC(_R_PAREN);
    break;

  case is_Atmtw:
    if (_i_ > 3) renderC(_L_PAREN);
    ppAtom(_p_->u.atmtw_.atom_, 0);

    if (_i_ > 3) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Scalar_exp!\n");
    exit(1);
  }
}

void ppListAtom(ListAtom listatom, int i)
{
  while(listatom!= 0)
  {
    if (listatom->listatom_ == 0)
    {
      ppAtom(listatom->atom_, 0);

      listatom = 0;
    }
    else
    {
      ppAtom(listatom->atom_, 0);
      renderC(',');
      listatom = listatom->listatom_;
    }
  }
}

void ppAtom(Atom _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Strng:
    if (_i_ > 0) renderC(_L_PAREN);
    ppString(_p_->u.strng_.string_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Decim:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.decim_.decimal_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Ipadd:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.ipadd_.ipadr_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Intgr:
    if (_i_ > 0) renderC(_L_PAREN);
    ppInteger(_p_->u.intgr_.integer_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Atom!\n");
    exit(1);
  }
}

void ppIn_predicate(In_predicate _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Innstq:
    if (_i_ > 0) renderC(_L_PAREN);
    ppScalar_exp(_p_->u.innstq_.scalar_exp_, 0);
    ppIdent(_p_->u.innstq_.in_, 0);
    ppNested_query(_p_->u.innstq_.nested_query_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Inostq:
    if (_i_ > 0) renderC(_L_PAREN);
    ppScalar_exp(_p_->u.inostq_.scalar_exp_, 0);
    ppIdent(_p_->u.inostq_.not_, 0);
    ppIdent(_p_->u.inostq_.in_, 0);
    ppNested_query(_p_->u.inostq_.nested_query_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Inatm:
    if (_i_ > 0) renderC(_L_PAREN);
    ppScalar_exp(_p_->u.inatm_.scalar_exp_, 0);
    ppIdent(_p_->u.inatm_.in_, 0);
    renderC('(');
    ppAtom(_p_->u.inatm_.atom_, 0);
    renderC(')');

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Inoatm:
    if (_i_ > 0) renderC(_L_PAREN);
    ppScalar_exp(_p_->u.inoatm_.scalar_exp_, 0);
    ppIdent(_p_->u.inoatm_.not_, 0);
    ppIdent(_p_->u.inoatm_.in_, 0);
    renderC('(');
    ppAtom(_p_->u.inoatm_.atom_, 0);
    renderC(')');

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing In_predicate!\n");
    exit(1);
  }
}

void ppExists_predicate(Exists_predicate _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Extnstq:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.extnstq_.exists_, 0);
    ppNested_query(_p_->u.extnstq_.nested_query_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Exists_predicate!\n");
    exit(1);
  }
}

void ppBetween_predicate(Between_predicate _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Bwsca:
    if (_i_ > 0) renderC(_L_PAREN);
    ppScalar_exp(_p_->u.bwsca_.scalar_exp_1, 0);
    ppIdent(_p_->u.bwsca_.between_, 0);
    ppScalar_exp(_p_->u.bwsca_.scalar_exp_2, 0);
    ppIdent(_p_->u.bwsca_.and_, 0);
    ppScalar_exp(_p_->u.bwsca_.scalar_exp_3, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Bwnosca:
    if (_i_ > 0) renderC(_L_PAREN);
    ppScalar_exp(_p_->u.bwnosca_.scalar_exp_1, 0);
    ppIdent(_p_->u.bwnosca_.not_, 0);
    ppIdent(_p_->u.bwnosca_.between_, 0);
    ppScalar_exp(_p_->u.bwnosca_.scalar_exp_2, 0);
    ppIdent(_p_->u.bwnosca_.and_, 0);
    ppScalar_exp(_p_->u.bwnosca_.scalar_exp_3, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Between_predicate!\n");
    exit(1);
  }
}

void ppLike_predicate(Like_predicate _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Lkstr:
    if (_i_ > 0) renderC(_L_PAREN);
    ppScalar_exp(_p_->u.lkstr_.scalar_exp_, 0);
    ppIdent(_p_->u.lkstr_.like_, 0);
    ppString(_p_->u.lkstr_.string_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Lknostr:
    if (_i_ > 0) renderC(_L_PAREN);
    ppScalar_exp(_p_->u.lknostr_.scalar_exp_, 0);
    ppIdent(_p_->u.lknostr_.not_, 0);
    ppIdent(_p_->u.lknostr_.like_, 0);
    ppString(_p_->u.lknostr_.string_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Like_predicate!\n");
    exit(1);
  }
}

void ppOptional_order_by_clause(Optional_order_by_clause _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Nordby:
    if (_i_ > 0) renderC(_L_PAREN);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Ordby:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.ordby_.order_, 0);
    ppIdent(_p_->u.ordby_.by_, 0);
    ppColumn_reference(_p_->u.ordby_.column_reference_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Optional_order_by_clause!\n");
    exit(1);
  }
}

void ppListColumn_reference(ListColumn_reference listcolumn_reference, int i)
{
  while(listcolumn_reference!= 0)
  {
    if (listcolumn_reference->listcolumn_reference_ == 0)
    {
      ppColumn_reference(listcolumn_reference->column_reference_, 0);

      listcolumn_reference = 0;
    }
    else
    {
      ppColumn_reference(listcolumn_reference->column_reference_, 0);
      renderC(',');
      listcolumn_reference = listcolumn_reference->listcolumn_reference_;
    }
  }
}

void ppOptional_group_by_clause(Optional_group_by_clause _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Nogrp:
    if (_i_ > 0) renderC(_L_PAREN);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Grpby:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.grpby_.group_, 0);
    ppIdent(_p_->u.grpby_.by_, 0);
    ppColumn_reference(_p_->u.grpby_.column_reference_, 0);
    ppOptional_ordering(_p_->u.grpby_.optional_ordering_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Optional_group_by_clause!\n");
    exit(1);
  }
}

void ppOptional_ordering(Optional_ordering _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Nord:
    if (_i_ > 0) renderC(_L_PAREN);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Ordasc:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.ordasc_.asc_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Orddsc:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.orddsc_.desc_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Optional_ordering!\n");
    exit(1);
  }
}

void ppOptional_having_clause(Optional_having_clause _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Nohvin:
    if (_i_ > 0) renderC(_L_PAREN);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Hvin:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.hvin_.having_, 0);
    ppAggregate_condition(_p_->u.hvin_.aggregate_condition_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Optional_having_clause!\n");
    exit(1);
  }
}

void ppAggregate_condition(Aggregate_condition _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Aggr:
    if (_i_ > 0) renderC(_L_PAREN);
    ppFunction_reference(_p_->u.aggr_.function_reference_, 0);
    ppComparison(_p_->u.aggr_.comparison_, 0);
    ppScalar_exp(_p_->u.aggr_.scalar_exp_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Aggregate_condition!\n");
    exit(1);
  }
}

void ppFunction_reference(Function_reference _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Funstr:
    if (_i_ > 0) renderC(_L_PAREN);
    ppFunction(_p_->u.funstr_.function_, 0);
    renderC('(');
    renderC('*');
    renderC(')');

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Fundist:
    if (_i_ > 0) renderC(_L_PAREN);
    ppFunction(_p_->u.fundist_.function_, 0);
    renderC('(');
    ppIdent(_p_->u.fundist_.distinct_, 0);
    ppColumn_reference(_p_->u.fundist_.column_reference_, 0);
    renderC(')');

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Funsca:
    if (_i_ > 0) renderC(_L_PAREN);
    ppFunction(_p_->u.funsca_.function_, 0);
    renderC('(');
    ppScalar_exp(_p_->u.funsca_.scalar_exp_, 0);
    renderC(')');

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Function_reference!\n");
    exit(1);
  }
}

void ppFunction(Function _p_, int _i_)
{
  switch(_p_->kind)
  {
  case is_Sum:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.sum_.sum_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Avg:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.avg_.avg_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Count:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.count_.count_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Max:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.max_.max_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;

  case is_Min:
    if (_i_ > 0) renderC(_L_PAREN);
    ppIdent(_p_->u.min_.min_, 0);

    if (_i_ > 0) renderC(_R_PAREN);
    break;


  default:
    fprintf(stderr, "Error: bad kind field when printing Function!\n");
    exit(1);
  }
}

void ppInteger(Integer n, int i)
{
  char tmp[16];
  sprintf(tmp, "%d", n);
  bufAppendS(tmp);
}
void ppDouble(Double d, int i)
{
  char tmp[16];
  sprintf(tmp, "%g", d);
  bufAppendS(tmp);
}
void ppChar(Char c, int i)
{
  bufAppendC('\'');
  bufAppendC(c);
  bufAppendC('\'');
}
void ppString(String s, int i)
{
  bufAppendC('\"');
  bufAppendS(s);
  bufAppendC('\"');
}
void ppIdent(String s, int i)
{
  renderS(s);
}

void shProgram(Program _p_)
{
  switch(_p_->kind)
  {
  case is_Progr:
  bufAppendC('(');

    bufAppendS("Progr");

  bufAppendC(' ');

    bufAppendC('[');
    shStatement(_p_->u.progr_.statement_);
    bufAppendC(']');

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Program!\n");
    exit(1);
  }
}

void shStatement(Statement _p_)
{
  switch(_p_->kind)
  {
  case is_Stmt:
  bufAppendC('(');

    bufAppendS("Stmt");

  bufAppendC(' ');

    bufAppendC('[');
    shQuery(_p_->u.stmt_.query_);
    bufAppendC(']');
  bufAppendC(' ');
    shIdent(_p_->u.stmt_.sc_);

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Statement!\n");
    exit(1);
  }
}

void shQuery(Query _p_)
{
  switch(_p_->kind)
  {
  case is_Qry:
  bufAppendC('(');

    bufAppendS("Qry");

  bufAppendC(' ');

    shIdent(_p_->u.qry_.select_);
  bufAppendC(' ');
    bufAppendC('[');
    shSpecifier(_p_->u.qry_.specifier_);
    bufAppendC(']');
  bufAppendC(' ');
    bufAppendC('[');
    shProjection(_p_->u.qry_.projection_);
    bufAppendC(']');
  bufAppendC(' ');
    shIdent(_p_->u.qry_.from_);
  bufAppendC(' ');
    bufAppendC('[');
    shVariable_declaration(_p_->u.qry_.variable_declaration_);
    bufAppendC(']');
  bufAppendC(' ');
    bufAppendC('[');
    shOptional_where_clause(_p_->u.qry_.optional_where_clause_);
    bufAppendC(']');
  bufAppendC(' ');
    bufAppendC('[');
    shOptional_group_by_clause(_p_->u.qry_.optional_group_by_clause_);
    bufAppendC(']');
  bufAppendC(' ');
    bufAppendC('[');
    shOptional_having_clause(_p_->u.qry_.optional_having_clause_);
    bufAppendC(']');
  bufAppendC(' ');
    bufAppendC('[');
    shOptional_order_by_clause(_p_->u.qry_.optional_order_by_clause_);
    bufAppendC(']');

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Query!\n");
    exit(1);
  }
}

void shNested_query(Nested_query _p_)
{
  switch(_p_->kind)
  {
  case is_NQry:
  bufAppendC('(');

    bufAppendS("NQry");

  bufAppendC(' ');

    bufAppendC('[');
    shQuery(_p_->u.nqry_.query_);
    bufAppendC(']');
  bufAppendC(' ');

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Nested_query!\n");
    exit(1);
  }
}

void shSpecifier(Specifier _p_)
{
  switch(_p_->kind)
  {
  case is_Nospe:

    bufAppendS("Nospe");




    break;

  case is_Distn:
  bufAppendC('(');

    bufAppendS("Distn");

  bufAppendC(' ');

    shIdent(_p_->u.distn_.distinct_);
  bufAppendC(' ');
    bufAppendC('[');
    shSpecifier(_p_->u.distn_.specifier_);
    bufAppendC(']');

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Specifier!\n");
    exit(1);
  }
}

void shListProjection(ListProjection listprojection)
{
  while(listprojection!= 0)
  {
    if (listprojection->listprojection_)
    {
      shProjection(listprojection->projection_);
      bufAppendS(", ");
      listprojection = listprojection->listprojection_;
    }
    else
    {
      shProjection(listprojection->projection_);
      listprojection = 0;
    }
  }
}

void shProjection(Projection _p_)
{
  switch(_p_->kind)
  {
  case is_Parprj:
  bufAppendC('(');

    bufAppendS("Parprj");

  bufAppendC(' ');

    bufAppendC('[');
    shProjection(_p_->u.parprj_.projection_);
    bufAppendC(']');
  bufAppendC(' ');

  bufAppendC(')');

    break;

  case is_Strprj:

    bufAppendS("Strprj");




    break;

  case is_Refprj:
  bufAppendC('(');

    bufAppendS("Refprj");

  bufAppendC(' ');

    bufAppendC('[');
    shReference(_p_->u.refprj_.reference_);
    bufAppendC(']');

  bufAppendC(')');

    break;

  case is_Idprj:
  bufAppendC('(');

    bufAppendS("Idprj");

  bufAppendC(' ');

    shIdent(_p_->u.idprj_.identifier_);
  bufAppendC(' ');
    bufAppendC('[');
    shReference(_p_->u.idprj_.reference_);
    bufAppendC(']');

  bufAppendC(')');

    break;

  case is_Asprj:
  bufAppendC('(');

    bufAppendS("Asprj");

  bufAppendC(' ');

    bufAppendC('[');
    shReference(_p_->u.asprj_.reference_);
    bufAppendC(']');
  bufAppendC(' ');
    shIdent(_p_->u.asprj_.as_);
  bufAppendC(' ');
    shIdent(_p_->u.asprj_.identifier_);

  bufAppendC(')');

    break;

  case is_Plusprj:
  bufAppendC('(');

    bufAppendS("Plusprj");

  bufAppendC(' ');

    shProjection(_p_->u.plusprj_.projection_1);
  bufAppendC(' ');
    shProjection(_p_->u.plusprj_.projection_2);

  bufAppendC(')');

    break;

  case is_Minprj:
  bufAppendC('(');

    bufAppendS("Minprj");

  bufAppendC(' ');

    shProjection(_p_->u.minprj_.projection_1);
  bufAppendC(' ');
    shProjection(_p_->u.minprj_.projection_2);

  bufAppendC(')');

    break;

  case is_Mulprj:
  bufAppendC('(');

    bufAppendS("Mulprj");

  bufAppendC(' ');

    shProjection(_p_->u.mulprj_.projection_1);
  bufAppendC(' ');
    shProjection(_p_->u.mulprj_.projection_2);

  bufAppendC(')');

    break;

  case is_Divprj:
  bufAppendC('(');

    bufAppendS("Divprj");

  bufAppendC(' ');

    shProjection(_p_->u.divprj_.projection_1);
  bufAppendC(' ');
    shProjection(_p_->u.divprj_.projection_2);

  bufAppendC(')');

    break;

  case is_Modprj:
  bufAppendC('(');

    bufAppendS("Modprj");

  bufAppendC(' ');

    shProjection(_p_->u.modprj_.projection_1);
  bufAppendC(' ');
    shIdent(_p_->u.modprj_.mod_);
  bufAppendC(' ');
    shProjection(_p_->u.modprj_.projection_2);

  bufAppendC(')');

    break;

  case is_Refprjtw:
  bufAppendC('(');

    bufAppendS("Refprjtw");

  bufAppendC(' ');

    bufAppendC('[');
    shReference(_p_->u.refprjtw_.reference_);
    bufAppendC(']');

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Projection!\n");
    exit(1);
  }
}

void shReference(Reference _p_)
{
  switch(_p_->kind)
  {
  case is_Colref:
  bufAppendC('(');

    bufAppendS("Colref");

  bufAppendC(' ');

    bufAppendC('[');
    shColumn_reference(_p_->u.colref_.column_reference_);
    bufAppendC(']');

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Reference!\n");
    exit(1);
  }
}

void shRererence(Rererence _p_)
{
  switch(_p_->kind)
  {
  case is_Funcref:
  bufAppendC('(');

    bufAppendS("Funcref");

  bufAppendC(' ');

    bufAppendC('[');
    shFunction_reference(_p_->u.funcref_.function_reference_);
    bufAppendC(']');

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Rererence!\n");
    exit(1);
  }
}

void shColumn_reference(Column_reference _p_)
{
  switch(_p_->kind)
  {
  case is_Name:
  bufAppendC('(');

    bufAppendS("Name");

  bufAppendC(' ');

    shIdent(_p_->u.name_.identifier_);

  bufAppendC(')');

    break;

  case is_Namenst:
  bufAppendC('(');

    bufAppendS("Namenst");

  bufAppendC(' ');

    bufAppendC('[');
    shColumn_reference(_p_->u.namenst_.column_reference_);
    bufAppendC(']');
  bufAppendC(' ');
    bufAppendC('[');
    shDot(_p_->u.namenst_.dot_);
    bufAppendC(']');
  bufAppendC(' ');
    shIdent(_p_->u.namenst_.identifier_);

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Column_reference!\n");
    exit(1);
  }
}

void shDot(Dot _p_)
{
  switch(_p_->kind)
  {
  case is_Dot:

    bufAppendS("Dot");




    break;

  case is_Ptr:
  bufAppendC('(');

    bufAppendS("Ptr");

  bufAppendC(' ');

    shIdent(_p_->u.ptr_.pointer_);

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Dot!\n");
    exit(1);
  }
}

void shListVariable_declaration(ListVariable_declaration listvariable_declaration)
{
  while(listvariable_declaration!= 0)
  {
    if (listvariable_declaration->listvariable_declaration_)
    {
      shVariable_declaration(listvariable_declaration->variable_declaration_);
      bufAppendS(", ");
      listvariable_declaration = listvariable_declaration->listvariable_declaration_;
    }
    else
    {
      shVariable_declaration(listvariable_declaration->variable_declaration_);
      listvariable_declaration = 0;
    }
  }
}

void shVariable_declaration(Variable_declaration _p_)
{
  switch(_p_->kind)
  {
  case is_Colrfas:
  bufAppendC('(');

    bufAppendS("Colrfas");

  bufAppendC(' ');

    bufAppendC('[');
    shColumn_reference(_p_->u.colrfas_.column_reference_);
    bufAppendC(']');
  bufAppendC(' ');
    shIdent(_p_->u.colrfas_.as_);
  bufAppendC(' ');
    shIdent(_p_->u.colrfas_.identifier_);

  bufAppendC(')');

    break;

  case is_Colrfin:
  bufAppendC('(');

    bufAppendS("Colrfin");

  bufAppendC(' ');

    shIdent(_p_->u.colrfin_.identifier_);
  bufAppendC(' ');
    shIdent(_p_->u.colrfin_.in_);
  bufAppendC(' ');
    bufAppendC('[');
    shColumn_reference(_p_->u.colrfin_.column_reference_);
    bufAppendC(']');

  bufAppendC(')');

    break;

  case is_Colrf:
  bufAppendC('(');

    bufAppendS("Colrf");

  bufAppendC(' ');

    bufAppendC('[');
    shColumn_reference(_p_->u.colrf_.column_reference_);
    bufAppendC(']');

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Variable_declaration!\n");
    exit(1);
  }
}

void shOptional_where_clause(Optional_where_clause _p_)
{
  switch(_p_->kind)
  {
  case is_Nowhr:

    bufAppendS("Nowhr");




    break;

  case is_Whrcls:
  bufAppendC('(');

    bufAppendS("Whrcls");

  bufAppendC(' ');

    shIdent(_p_->u.whrcls_.where_);
  bufAppendC(' ');
    bufAppendC('[');
    shCondition(_p_->u.whrcls_.condition_);
    bufAppendC(']');

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Optional_where_clause!\n");
    exit(1);
  }
}

void shCondition(Condition _p_)
{
  switch(_p_->kind)
  {
  case is_Paracnd:
  bufAppendC('(');

    bufAppendS("Paracnd");

  bufAppendC(' ');

    bufAppendC('[');
    shCondition(_p_->u.paracnd_.condition_);
    bufAppendC(']');
  bufAppendC(' ');

  bufAppendC(')');

    break;

  case is_Andcnd:
  bufAppendC('(');

    bufAppendS("Andcnd");

  bufAppendC(' ');

    shCondition(_p_->u.andcnd_.condition_1);
  bufAppendC(' ');
    shIdent(_p_->u.andcnd_.and_);
  bufAppendC(' ');
    shCondition(_p_->u.andcnd_.condition_2);

  bufAppendC(')');

    break;

  case is_Orcnd:
  bufAppendC('(');

    bufAppendS("Orcnd");

  bufAppendC(' ');

    shCondition(_p_->u.orcnd_.condition_1);
  bufAppendC(' ');
    shIdent(_p_->u.orcnd_.or_);
  bufAppendC(' ');
    shCondition(_p_->u.orcnd_.condition_2);

  bufAppendC(')');

    break;

  case is_Notcnd:
  bufAppendC('(');

    bufAppendS("Notcnd");

  bufAppendC(' ');

    shIdent(_p_->u.notcnd_.not_);
  bufAppendC(' ');
    bufAppendC('[');
    shCondition(_p_->u.notcnd_.condition_);
    bufAppendC(']');

  bufAppendC(')');

    break;

  case is_Predcnd:
  bufAppendC('(');

    bufAppendS("Predcnd");

  bufAppendC(' ');

    bufAppendC('[');
    shPredicate(_p_->u.predcnd_.predicate_);
    bufAppendC(']');

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Condition!\n");
    exit(1);
  }
}

void shPredicate(Predicate _p_)
{
  switch(_p_->kind)
  {
  case is_Comp:
  bufAppendC('(');

    bufAppendS("Comp");

  bufAppendC(' ');

    bufAppendC('[');
    shComparison_predicate(_p_->u.comp_.comparison_predicate_);
    bufAppendC(']');

  bufAppendC(')');

    break;

  case is_In:
  bufAppendC('(');

    bufAppendS("In");

  bufAppendC(' ');

    bufAppendC('[');
    shIn_predicate(_p_->u.in_.in_predicate_);
    bufAppendC(']');

  bufAppendC(')');

    break;

  case is_Exts:
  bufAppendC('(');

    bufAppendS("Exts");

  bufAppendC(' ');

    bufAppendC('[');
    shExists_predicate(_p_->u.exts_.exists_predicate_);
    bufAppendC(']');

  bufAppendC(')');

    break;

  case is_Bwn:
  bufAppendC('(');

    bufAppendS("Bwn");

  bufAppendC(' ');

    bufAppendC('[');
    shBetween_predicate(_p_->u.bwn_.between_predicate_);
    bufAppendC(']');

  bufAppendC(')');

    break;

  case is_Lik:
  bufAppendC('(');

    bufAppendS("Lik");

  bufAppendC(' ');

    bufAppendC('[');
    shLike_predicate(_p_->u.lik_.like_predicate_);
    bufAppendC(']');

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Predicate!\n");
    exit(1);
  }
}

void shComparison_predicate(Comparison_predicate _p_)
{
  switch(_p_->kind)
  {
  case is_CompSca:
  bufAppendC('(');

    bufAppendS("CompSca");

  bufAppendC(' ');

    shScalar_exp(_p_->u.compsca_.scalar_exp_1);
  bufAppendC(' ');
    bufAppendC('[');
    shComparison(_p_->u.compsca_.comparison_);
    bufAppendC(']');
  bufAppendC(' ');
    shScalar_exp(_p_->u.compsca_.scalar_exp_2);

  bufAppendC(')');

    break;

  case is_CompNst:
  bufAppendC('(');

    bufAppendS("CompNst");

  bufAppendC(' ');

    bufAppendC('[');
    shScalar_exp(_p_->u.compnst_.scalar_exp_);
    bufAppendC(']');
  bufAppendC(' ');
    bufAppendC('[');
    shComparison(_p_->u.compnst_.comparison_);
    bufAppendC(']');
  bufAppendC(' ');
    bufAppendC('[');
    shNested_query(_p_->u.compnst_.nested_query_);
    bufAppendC(']');

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Comparison_predicate!\n");
    exit(1);
  }
}

void shComparison(Comparison _p_)
{
  switch(_p_->kind)
  {
  case is_Eq:

    bufAppendS("Eq");




    break;

  case is_Neq:

    bufAppendS("Neq");




    break;

  case is_Lt:

    bufAppendS("Lt");




    break;

  case is_Gt:

    bufAppendS("Gt");




    break;

  case is_Leq:
  bufAppendC('(');

    bufAppendS("Leq");

  bufAppendC(' ');

    shIdent(_p_->u.leq_.le_);

  bufAppendC(')');

    break;

  case is_Geq:
  bufAppendC('(');

    bufAppendS("Geq");

  bufAppendC(' ');

    shIdent(_p_->u.geq_.ge_);

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Comparison!\n");
    exit(1);
  }
}

void shScalar_exp(Scalar_exp _p_)
{
  switch(_p_->kind)
  {
  case is_Atm:
  bufAppendC('(');

    bufAppendS("Atm");

  bufAppendC(' ');

    bufAppendC('[');
    shAtom(_p_->u.atm_.atom_);
    bufAppendC(']');

  bufAppendC(')');

    break;

  case is_Colrftw:
  bufAppendC('(');

    bufAppendS("Colrftw");

  bufAppendC(' ');

    bufAppendC('[');
    shColumn_reference(_p_->u.colrftw_.column_reference_);
    bufAppendC(']');

  bufAppendC(')');

    break;

  case is_Parsca:
  bufAppendC('(');

    bufAppendS("Parsca");

  bufAppendC(' ');

    bufAppendC('[');
    shScalar_exp(_p_->u.parsca_.scalar_exp_);
    bufAppendC(']');
  bufAppendC(' ');

  bufAppendC(')');

    break;

  case is_Addsca:
  bufAppendC('(');

    bufAppendS("Addsca");

  bufAppendC(' ');

    shScalar_exp(_p_->u.addsca_.scalar_exp_1);
  bufAppendC(' ');
    shScalar_exp(_p_->u.addsca_.scalar_exp_2);

  bufAppendC(')');

    break;

  case is_Subsca:
  bufAppendC('(');

    bufAppendS("Subsca");

  bufAppendC(' ');

    shScalar_exp(_p_->u.subsca_.scalar_exp_1);
  bufAppendC(' ');
    shScalar_exp(_p_->u.subsca_.scalar_exp_2);

  bufAppendC(')');

    break;

  case is_Mulsca:
  bufAppendC('(');

    bufAppendS("Mulsca");

  bufAppendC(' ');

    shScalar_exp(_p_->u.mulsca_.scalar_exp_1);
  bufAppendC(' ');
    shScalar_exp(_p_->u.mulsca_.scalar_exp_2);

  bufAppendC(')');

    break;

  case is_Divsca:
  bufAppendC('(');

    bufAppendS("Divsca");

  bufAppendC(' ');

    shScalar_exp(_p_->u.divsca_.scalar_exp_1);
  bufAppendC(' ');
    shIdent(_p_->u.divsca_.mod_);
  bufAppendC(' ');
    shScalar_exp(_p_->u.divsca_.scalar_exp_2);

  bufAppendC(')');

    break;

  case is_Andsca:
  bufAppendC('(');

    bufAppendS("Andsca");

  bufAppendC(' ');

    shScalar_exp(_p_->u.andsca_.scalar_exp_1);
  bufAppendC(' ');
    shScalar_exp(_p_->u.andsca_.scalar_exp_2);

  bufAppendC(')');

    break;

  case is_Orsca:
  bufAppendC('(');

    bufAppendS("Orsca");

  bufAppendC(' ');

    shScalar_exp(_p_->u.orsca_.scalar_exp_1);
  bufAppendC(' ');
    shScalar_exp(_p_->u.orsca_.scalar_exp_2);

  bufAppendC(')');

    break;

  case is_Notsca:
  bufAppendC('(');

    bufAppendS("Notsca");

  bufAppendC(' ');

    shScalar_exp(_p_->u.notsca_.scalar_exp_1);
  bufAppendC(' ');
    shScalar_exp(_p_->u.notsca_.scalar_exp_2);

  bufAppendC(')');

    break;

  case is_Lssca:
  bufAppendC('(');

    bufAppendS("Lssca");

  bufAppendC(' ');

    shScalar_exp(_p_->u.lssca_.scalar_exp_1);
  bufAppendC(' ');
    shIdent(_p_->u.lssca_.ls_);
  bufAppendC(' ');
    shScalar_exp(_p_->u.lssca_.scalar_exp_2);

  bufAppendC(')');

    break;

  case is_Rssca:
  bufAppendC('(');

    bufAppendS("Rssca");

  bufAppendC(' ');

    shScalar_exp(_p_->u.rssca_.scalar_exp_1);
  bufAppendC(' ');
    shIdent(_p_->u.rssca_.rs_);
  bufAppendC(' ');
    shScalar_exp(_p_->u.rssca_.scalar_exp_2);

  bufAppendC(')');

    break;

  case is_Atmtw:
  bufAppendC('(');

    bufAppendS("Atmtw");

  bufAppendC(' ');

    bufAppendC('[');
    shAtom(_p_->u.atmtw_.atom_);
    bufAppendC(']');

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Scalar_exp!\n");
    exit(1);
  }
}

void shListAtom(ListAtom listatom)
{
  while(listatom!= 0)
  {
    if (listatom->listatom_)
    {
      shAtom(listatom->atom_);
      bufAppendS(", ");
      listatom = listatom->listatom_;
    }
    else
    {
      shAtom(listatom->atom_);
      listatom = 0;
    }
  }
}

void shAtom(Atom _p_)
{
  switch(_p_->kind)
  {
  case is_Strng:
  bufAppendC('(');

    bufAppendS("Strng");

  bufAppendC(' ');

    shString(_p_->u.strng_.string_);

  bufAppendC(')');

    break;

  case is_Decim:
  bufAppendC('(');

    bufAppendS("Decim");

  bufAppendC(' ');

    shIdent(_p_->u.decim_.decimal_);

  bufAppendC(')');

    break;

  case is_Ipadd:
  bufAppendC('(');

    bufAppendS("Ipadd");

  bufAppendC(' ');

    shIdent(_p_->u.ipadd_.ipadr_);

  bufAppendC(')');

    break;

  case is_Intgr:
  bufAppendC('(');

    bufAppendS("Intgr");

  bufAppendC(' ');

    shInteger(_p_->u.intgr_.integer_);

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Atom!\n");
    exit(1);
  }
}

void shIn_predicate(In_predicate _p_)
{
  switch(_p_->kind)
  {
  case is_Innstq:
  bufAppendC('(');

    bufAppendS("Innstq");

  bufAppendC(' ');

    bufAppendC('[');
    shScalar_exp(_p_->u.innstq_.scalar_exp_);
    bufAppendC(']');
  bufAppendC(' ');
    shIdent(_p_->u.innstq_.in_);
  bufAppendC(' ');
    bufAppendC('[');
    shNested_query(_p_->u.innstq_.nested_query_);
    bufAppendC(']');

  bufAppendC(')');

    break;

  case is_Inostq:
  bufAppendC('(');

    bufAppendS("Inostq");

  bufAppendC(' ');

    bufAppendC('[');
    shScalar_exp(_p_->u.inostq_.scalar_exp_);
    bufAppendC(']');
  bufAppendC(' ');
    shIdent(_p_->u.inostq_.not_);
  bufAppendC(' ');
    shIdent(_p_->u.inostq_.in_);
  bufAppendC(' ');
    bufAppendC('[');
    shNested_query(_p_->u.inostq_.nested_query_);
    bufAppendC(']');

  bufAppendC(')');

    break;

  case is_Inatm:
  bufAppendC('(');

    bufAppendS("Inatm");

  bufAppendC(' ');

    bufAppendC('[');
    shScalar_exp(_p_->u.inatm_.scalar_exp_);
    bufAppendC(']');
  bufAppendC(' ');
    shIdent(_p_->u.inatm_.in_);
  bufAppendC(' ');
    bufAppendC('[');
    shAtom(_p_->u.inatm_.atom_);
    bufAppendC(']');
  bufAppendC(' ');

  bufAppendC(')');

    break;

  case is_Inoatm:
  bufAppendC('(');

    bufAppendS("Inoatm");

  bufAppendC(' ');

    bufAppendC('[');
    shScalar_exp(_p_->u.inoatm_.scalar_exp_);
    bufAppendC(']');
  bufAppendC(' ');
    shIdent(_p_->u.inoatm_.not_);
  bufAppendC(' ');
    shIdent(_p_->u.inoatm_.in_);
  bufAppendC(' ');
    bufAppendC('[');
    shAtom(_p_->u.inoatm_.atom_);
    bufAppendC(']');
  bufAppendC(' ');

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing In_predicate!\n");
    exit(1);
  }
}

void shExists_predicate(Exists_predicate _p_)
{
  switch(_p_->kind)
  {
  case is_Extnstq:
  bufAppendC('(');

    bufAppendS("Extnstq");

  bufAppendC(' ');

    shIdent(_p_->u.extnstq_.exists_);
  bufAppendC(' ');
    bufAppendC('[');
    shNested_query(_p_->u.extnstq_.nested_query_);
    bufAppendC(']');

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Exists_predicate!\n");
    exit(1);
  }
}

void shBetween_predicate(Between_predicate _p_)
{
  switch(_p_->kind)
  {
  case is_Bwsca:
  bufAppendC('(');

    bufAppendS("Bwsca");

  bufAppendC(' ');

    shScalar_exp(_p_->u.bwsca_.scalar_exp_1);
  bufAppendC(' ');
    shIdent(_p_->u.bwsca_.between_);
  bufAppendC(' ');
    shScalar_exp(_p_->u.bwsca_.scalar_exp_2);
  bufAppendC(' ');
    shIdent(_p_->u.bwsca_.and_);
  bufAppendC(' ');
    shScalar_exp(_p_->u.bwsca_.scalar_exp_3);

  bufAppendC(')');

    break;

  case is_Bwnosca:
  bufAppendC('(');

    bufAppendS("Bwnosca");

  bufAppendC(' ');

    shScalar_exp(_p_->u.bwnosca_.scalar_exp_1);
  bufAppendC(' ');
    shIdent(_p_->u.bwnosca_.not_);
  bufAppendC(' ');
    shIdent(_p_->u.bwnosca_.between_);
  bufAppendC(' ');
    shScalar_exp(_p_->u.bwnosca_.scalar_exp_2);
  bufAppendC(' ');
    shIdent(_p_->u.bwnosca_.and_);
  bufAppendC(' ');
    shScalar_exp(_p_->u.bwnosca_.scalar_exp_3);

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Between_predicate!\n");
    exit(1);
  }
}

void shLike_predicate(Like_predicate _p_)
{
  switch(_p_->kind)
  {
  case is_Lkstr:
  bufAppendC('(');

    bufAppendS("Lkstr");

  bufAppendC(' ');

    bufAppendC('[');
    shScalar_exp(_p_->u.lkstr_.scalar_exp_);
    bufAppendC(']');
  bufAppendC(' ');
    shIdent(_p_->u.lkstr_.like_);
  bufAppendC(' ');
    shString(_p_->u.lkstr_.string_);

  bufAppendC(')');

    break;

  case is_Lknostr:
  bufAppendC('(');

    bufAppendS("Lknostr");

  bufAppendC(' ');

    bufAppendC('[');
    shScalar_exp(_p_->u.lknostr_.scalar_exp_);
    bufAppendC(']');
  bufAppendC(' ');
    shIdent(_p_->u.lknostr_.not_);
  bufAppendC(' ');
    shIdent(_p_->u.lknostr_.like_);
  bufAppendC(' ');
    shString(_p_->u.lknostr_.string_);

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Like_predicate!\n");
    exit(1);
  }
}

void shOptional_order_by_clause(Optional_order_by_clause _p_)
{
  switch(_p_->kind)
  {
  case is_Nordby:

    bufAppendS("Nordby");




    break;

  case is_Ordby:
  bufAppendC('(');

    bufAppendS("Ordby");

  bufAppendC(' ');

    shIdent(_p_->u.ordby_.order_);
  bufAppendC(' ');
    shIdent(_p_->u.ordby_.by_);
  bufAppendC(' ');
    bufAppendC('[');
    shColumn_reference(_p_->u.ordby_.column_reference_);
    bufAppendC(']');

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Optional_order_by_clause!\n");
    exit(1);
  }
}

void shListColumn_reference(ListColumn_reference listcolumn_reference)
{
  while(listcolumn_reference!= 0)
  {
    if (listcolumn_reference->listcolumn_reference_)
    {
      shColumn_reference(listcolumn_reference->column_reference_);
      bufAppendS(", ");
      listcolumn_reference = listcolumn_reference->listcolumn_reference_;
    }
    else
    {
      shColumn_reference(listcolumn_reference->column_reference_);
      listcolumn_reference = 0;
    }
  }
}

void shOptional_group_by_clause(Optional_group_by_clause _p_)
{
  switch(_p_->kind)
  {
  case is_Nogrp:

    bufAppendS("Nogrp");




    break;

  case is_Grpby:
  bufAppendC('(');

    bufAppendS("Grpby");

  bufAppendC(' ');

    shIdent(_p_->u.grpby_.group_);
  bufAppendC(' ');
    shIdent(_p_->u.grpby_.by_);
  bufAppendC(' ');
    bufAppendC('[');
    shColumn_reference(_p_->u.grpby_.column_reference_);
    bufAppendC(']');
  bufAppendC(' ');
    bufAppendC('[');
    shOptional_ordering(_p_->u.grpby_.optional_ordering_);
    bufAppendC(']');

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Optional_group_by_clause!\n");
    exit(1);
  }
}

void shOptional_ordering(Optional_ordering _p_)
{
  switch(_p_->kind)
  {
  case is_Nord:

    bufAppendS("Nord");




    break;

  case is_Ordasc:
  bufAppendC('(');

    bufAppendS("Ordasc");

  bufAppendC(' ');

    shIdent(_p_->u.ordasc_.asc_);

  bufAppendC(')');

    break;

  case is_Orddsc:
  bufAppendC('(');

    bufAppendS("Orddsc");

  bufAppendC(' ');

    shIdent(_p_->u.orddsc_.desc_);

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Optional_ordering!\n");
    exit(1);
  }
}

void shOptional_having_clause(Optional_having_clause _p_)
{
  switch(_p_->kind)
  {
  case is_Nohvin:

    bufAppendS("Nohvin");




    break;

  case is_Hvin:
  bufAppendC('(');

    bufAppendS("Hvin");

  bufAppendC(' ');

    shIdent(_p_->u.hvin_.having_);
  bufAppendC(' ');
    bufAppendC('[');
    shAggregate_condition(_p_->u.hvin_.aggregate_condition_);
    bufAppendC(']');

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Optional_having_clause!\n");
    exit(1);
  }
}

void shAggregate_condition(Aggregate_condition _p_)
{
  switch(_p_->kind)
  {
  case is_Aggr:
  bufAppendC('(');

    bufAppendS("Aggr");

  bufAppendC(' ');

    bufAppendC('[');
    shFunction_reference(_p_->u.aggr_.function_reference_);
    bufAppendC(']');
  bufAppendC(' ');
    bufAppendC('[');
    shComparison(_p_->u.aggr_.comparison_);
    bufAppendC(']');
  bufAppendC(' ');
    bufAppendC('[');
    shScalar_exp(_p_->u.aggr_.scalar_exp_);
    bufAppendC(']');

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Aggregate_condition!\n");
    exit(1);
  }
}

void shFunction_reference(Function_reference _p_)
{
  switch(_p_->kind)
  {
  case is_Funstr:
  bufAppendC('(');

    bufAppendS("Funstr");

  bufAppendC(' ');

    bufAppendC('[');
    shFunction(_p_->u.funstr_.function_);
    bufAppendC(']');
  bufAppendC(' ');

  bufAppendC(')');

    break;

  case is_Fundist:
  bufAppendC('(');

    bufAppendS("Fundist");

  bufAppendC(' ');

    bufAppendC('[');
    shFunction(_p_->u.fundist_.function_);
    bufAppendC(']');
  bufAppendC(' ');
    shIdent(_p_->u.fundist_.distinct_);
  bufAppendC(' ');
    bufAppendC('[');
    shColumn_reference(_p_->u.fundist_.column_reference_);
    bufAppendC(']');
  bufAppendC(' ');

  bufAppendC(')');

    break;

  case is_Funsca:
  bufAppendC('(');

    bufAppendS("Funsca");

  bufAppendC(' ');

    bufAppendC('[');
    shFunction(_p_->u.funsca_.function_);
    bufAppendC(']');
  bufAppendC(' ');
    bufAppendC('[');
    shScalar_exp(_p_->u.funsca_.scalar_exp_);
    bufAppendC(']');
  bufAppendC(' ');

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Function_reference!\n");
    exit(1);
  }
}

void shFunction(Function _p_)
{
  switch(_p_->kind)
  {
  case is_Sum:
  bufAppendC('(');

    bufAppendS("Sum");

  bufAppendC(' ');

    shIdent(_p_->u.sum_.sum_);

  bufAppendC(')');

    break;

  case is_Avg:
  bufAppendC('(');

    bufAppendS("Avg");

  bufAppendC(' ');

    shIdent(_p_->u.avg_.avg_);

  bufAppendC(')');

    break;

  case is_Count:
  bufAppendC('(');

    bufAppendS("Count");

  bufAppendC(' ');

    shIdent(_p_->u.count_.count_);

  bufAppendC(')');

    break;

  case is_Max:
  bufAppendC('(');

    bufAppendS("Max");

  bufAppendC(' ');

    shIdent(_p_->u.max_.max_);

  bufAppendC(')');

    break;

  case is_Min:
  bufAppendC('(');

    bufAppendS("Min");

  bufAppendC(' ');

    shIdent(_p_->u.min_.min_);

  bufAppendC(')');

    break;


  default:
    fprintf(stderr, "Error: bad kind field when showing Function!\n");
    exit(1);
  }
}

void shInteger(Integer i)
{
  char tmp[16];
  sprintf(tmp, "%d", i);
  bufAppendS(tmp);
}
void shDouble(Double d)
{
  char tmp[16];
  sprintf(tmp, "%g", d);
  bufAppendS(tmp);
}
void shChar(Char c)
{
  bufAppendC('\'');
  bufAppendC(c);
  bufAppendC('\'');
}
void shString(String s)
{
  bufAppendC('\"');
  bufAppendS(s);
  bufAppendC('\"');
}
void shIdent(String s)
{
  bufAppendC('\"');
  bufAppendS(s);
  bufAppendC('\"');
}

void bufAppendS(const char* s)
{
  int len = strlen(s);
  int n;
  while (cur_ + len > buf_size)
  {
    buf_size *= 2; /* Double the buffer size */
    resizeBuffer();
  }
  for(n = 0; n < len; n++)
  {
    buf_[cur_ + n] = s[n];
  }
  cur_ += len;
  buf_[cur_] = 0;
}
void bufAppendC(const char c)
{
  if (cur_ == buf_size)
  {
    buf_size *= 2; /* Double the buffer size */
    resizeBuffer();
  }
  buf_[cur_] = c;
  cur_++;
  buf_[cur_] = 0;
}
void bufReset(void)
{
  cur_ = 0;
  buf_size = BUFFER_INITIAL;
  resizeBuffer();
  memset(buf_, 0, buf_size);
}
void resizeBuffer(void)
{
  char* temp = (char*) malloc(buf_size);
  if (!temp)
  {
    fprintf(stderr, "Error: Out of memory while attempting to grow buffer!\n");
    exit(1);
  }
  if (buf_)
  {
    strncpy(temp, buf_, buf_size); /* peteg: strlcpy is safer, but not POSIX/ISO C. */
    free(buf_);
  }
  buf_ = temp;
}
char *buf_;
int cur_, buf_size;

